<?php 
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$info = pdo_get('snx_school',array('id'=>$_GPC['id']));
if(checksubmit('submit')){
        $data['cate_name']=$_GPC['cate_name'];
        $data['address']=$_GPC['address'];
        $data['phone']=$_GPC['phone'];
        $data['create_time']=date('Y-m-d H:i:s',time());
        $data['state'] = 2;
        $data['uniacid']=$_W['uniacid'];
        if (empty($_GPC['cate_name'])) {
             message('校区名称不能为空','','error');
        }if(empty($_GPC['address'])){
             message('校区地址不能为空','','error');
        }if(empty($_GPC['phone'])){
             message('联系电话不能为空','','error');
        }if(preg_match("/^1[34578]\d{9}$/", $phone)){
             message('联系电话不正确','','error');
        }
     if($_GPC['id']==''){
        $roe = pdo_getall("snx_school",array('cate_name'=>$_GPC['cate_name'],'address'=>$_GPC['address']),array('cate_name','address'));
          if (!empty($roe)) {
                  message('该校区已存在','','error');
              }
              $catename = trim($_GPC['cate_name'],' ');
              if ($catename== "新用户") {
                        $arr['cate_name']=$_GPC['cate_name'];
                        $arr['address']=$_GPC['address'];
                        $arr['phone']=$_GPC['phone'];
                        $arr['create_time']=date('Y-m-d H:i:s',time());
                        $arr['state'] = 1;
                        $arr['uniacid']=$_W['uniacid'];
                    $test=pdo_insert('snx_school',$arr);      
                    if($test){
                         message('添加成功！', $this->createWebUrl('school'), 'success');
                    }else{
                         message('添加失败！','','error');
                    }
              }else{
                $rst=pdo_insert('snx_school',$data);      
                if($rst){
                     message('添加成功！', $this->createWebUrl('school'), 'success');
                }else{
                     message('添加失败！','','error');
                }
              }
            
    }else{
        $roe = pdo_getall("snx_school",array('cate_name'=>$_GPC['cate_name'],'address'=>$_GPC['address'],'phone'=>$_GPC['phone']),array('cate_name','address'));
          if (!empty($roe)) {
                  message('该校区已存在','','error');
              }
        $rst=pdo_update('snx_school',$data,array('id'=>$_GPC['id']));
        if($rst){
             message('编辑成功！', $this->createWebUrl('school'), 'success');
        }else{
             message('编辑失败！','','error');
        }
    }
}
include $this->template('web/addschool');
 ?>